﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace HowItWentDown
{
    public class CustomEffect : Effect
    {
        GraphicsDevice graphics;
        Texture2D texture;
        Matrix world, view, proj;
        float alpha;
        Color col;
        public bool Highlight = false;
        public Color HighlightColor = Color.Red;
        public Color FogColor = Color.White;
        public float FogStart = 0, FogEnd = 800, Bloom = 0;
        public float Alpha
        {
            set { Parameters["Alpha"].SetValue(value); alpha = value; }
        }
        public Texture2D Texture
        {
            set 
            { 
                Parameters["Texture"].SetValue(value); 
                texture = value; 
            }
        }
        public Matrix World
        {
            set { Parameters["World"].SetValue(value); world = value; }
            get { return world; }
        }
        public Matrix View
        {
            set { Parameters["View"].SetValue(value); view = value; }
            get { return view; }
        }
        public Matrix Projection
        {
            set { Parameters["Projection"].SetValue(value); proj = value; }
            get { return proj; }
        }
        /// <summary>
        /// Sets the color objects will be drawn at
        /// </summary>
        public Color Color
        {
            set { Parameters["Color"].SetValue(value.ToVector4()); col = value; }
        }
        public CustomEffect(GraphicsDevice graph)
            :base(Global.LoadEffect("CustomShader"))
        {
            graphics = graph;
            CurrentTechnique = Techniques["WithBlurAndOutline"];
        }
        public void UpdateTechnique()
        {
            switch (Global.Effects)
            {
                default:
                    CurrentTechnique = Techniques["NoBlur"];
                    break;
                case Effects.Blur:
                    if (Highlight)
                    CurrentTechnique = Techniques["WithBlurAndOutline"];
                    else CurrentTechnique = Techniques["WithBlur"];
                    break;
            }
        }
        protected override void OnApply()
        {
            Parameters["Color"].SetValue(col.ToVector4());
            Parameters["HighlightColor"].SetValue(HighlightColor.ToVector4());
            Parameters["Bloom"].SetValue(Bloom);
            Parameters["World"].SetValue(world);
            Parameters["FogColor"].SetValue(FogColor.ToVector4());
            Parameters["FogStart"].SetValue(FogStart); Parameters["FogEnd"].SetValue(FogEnd);
            base.OnApply();
        }
    }
}
